package com.btt.pattern.proxy.custom;

import com.btt.pattern.proxy.statics.Person;
import com.sun.org.apache.bcel.internal.util.ClassLoader;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * created by Btt on 2018/07/03
 */

public class CustomMeiPo implements BTInvocationHandler {

    //被代理的对象，把引用给保存下来
    private Person target;

    public Object getInstance(Person target) throws Exception{

        this.target = target;
        Class<?> c = target.getClass();
        return BTProxy.newProxyInstance(new BTClassLoader(), c.getInterfaces(), this);

    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是媒婆：我要给你找对象，现在已经拿到你需求");
        System.out.println("开始物色");

        method.invoke(this.target, args);

        System.out.println("见面，谈恋爱");
        return null;
    }
}
